﻿@model  Model.PageRole
@{
    ViewBag.Title = "推送模型列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script src="/Scripts/TargetConfig.js" type="text/javascript"></script>
    <script type="text/javascript">
        var UrlArray = $.getUrlArray();
        var pageRole = '@Model.role';
        $(function () {
            if (UrlArray["DBType"] == "2") {
                $(".sapsavedModel").html("源表");
                $("#btnAddModel").val("导入源表");
            }
            InitList();
        });
        function btnBack_Click() {
            var url = "";
            if (UrlArray["DBType"] == "2")
                url += "&DBType=" + UrlArray["DBType"];
            goto("/EtlTarget/EtlTargetViewConfig?systemID=" + UrlArray["systemID"] + "&dbName=" + encodeURI(UrlArray["dbName"]) + url);
        }

        function btnAddModel_Click() {
            var groupID = UrlArray["groupID"];
            selectModelToGroup(groupID);
        }
        var pushName = new Array();
        var para = {
            rows: 18,
            height: 400,
            url: "/ViewGroup/GetViewModelInGroup?dbName=" + encodeURI(UrlArray["dbName"]),
            para: { systemID: UrlArray["systemID"], groupID: UrlArray["groupID"] },
            idField: "Guid",
            checkbox: false,
            rownumbers: true,
            columns: [
                    { field: 'MDP_ViewName', title: '模型名称', width: 35, sortable: true },
                    { field: 'PushName', title: '推送名称', width: 30, sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            if (rowData.PushSchema) {
                                return rowData.PushSchema + "." + value;
                            } else
                                return value;
                        }
                    }, 
                    { field: 'ETLStatus', title: '任务状态', width: 10, sortable: true, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            if (value == "2")
                                return "<img src='/images/stepok.png' />";
                            else
                                return "<img src='/images/steperr.png' />";
                        }
                    },
                    { field: 'CreateTime', title: '创建时间', width: 10, align: 'center', sortable: true },
                    { field: 'Guid', title: '操作', width: 15, align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            var add = true; ;
                            for (var j = 0; j < pushName.length; j++) {
                                if (pushName[j].Guid == rowData.Guid) {
                                    add = false;
                                }
                            }
                            if (add) {
                                pushName.push(rowData);
                            }
                            var a = "<select onchange=\"onModelDoAction(this.options.selectedIndex,'" + value + "')\"><option value=''>-请选择-</option>";
                            if (pageRole == '2') {
                                var coll = "";
                                if (rowData.CollectionType > 0)
                                    coll = "<option>查看映射字段</option><option>配置映射表</option>";
                                return a + "<option>导出建表语句</option><option>编辑推送名称</option><option>取消与组关联</option><option>配置模型字段</option><option>取消配置字段</option><option>删除</option><option>查看任务状态</option><option>跟踪</option>" + coll + "</select>";
                            }
                            else {
                                return a + "<option>导出建表语句</option><option>查看任务状态</option><option>跟踪</option></select>";
                            }
                        }
                    }
                ]
        };
        function InitList(postUrl) {  
            if (UrlArray["DBType"] == "2") {
                para.columns[0].title = "源表名称";
            }
            $("#DataGrid").dg(para);
        }

        // 模型事件
        function onModelDoAction(i, value) {
            if (pageRole == '1' && i > 1) {
                i = i + 5;
            }
            switch (i) {
                case 1: //  导出建表语句
                    exportViewCreateTableScript(value);
                    break;
                case 2: // 编辑推送名称 
                    editPushName(value);
                    break;
                case 3: // 取消与组关联
                    removeModelFromGroup(value, true);
                    break;
                case 4:
                    openColumnConfigPage(value); // 配置模型字段
                    break;
                case 5:
                    deleteColumnConfig(value, "removeGroup"); // 取消配置字段  
                    break;
                case 6:
                    deleteTargetView(value);
                    break;
                case 7:
                    ViewETLData(value);
                    break;
                case 8:
                    GetPath(value, 'target', 0);
                    break;
                case 9: 
                    ViewMappingData(value);
                    break;
                case 10: 
                    EditMappingData(value);
                    break;
            }
            InitList();
        }
        function ViewMappingData(v) {
            showModalMany('EditMappingData', '/EtlTarget/ViewMappingData?systemID=' + UrlArray["systemID"] + "&viewID=" + v + '&dbName=' + encodeURI(UrlArray["dbName"] + "&DBType=2"), '800', '480');
        }
        function EditMappingData(v) {
            showModalMany('EditMappingData', '/ODSConfig/SourceList?tarSysID=' + UrlArray["systemID"] + "&viewID=" + v + '&dbName=' + encodeURI(UrlArray["dbName"] + "&DBType=2&mpedit=1"), '900', '480');
        }
    </script>
    <style>
        .viewPushName
        {
            position: absolute;
            top: 65px;
            left: 350px;
            background: #ffffff;
            width: 450px;
            height: 120px;
            display: none;
            z-index: 1002;
        }
    </style>
}
<div style="margin: 5px;">
    @{
        // 渲染输出列表
        var dataGrid = new ViewDataDictionary();
        dataGrid.Add("PanelTitle", "推送模型列表");
        dataGrid.Add("GridID", "DataGrid");
        dataGrid.Add("ShowAddButton", false);
        dataGrid.Add("ShowDeleteButton", false);
        if (Model.role == 2)
        {
            dataGrid.Add("ShowOtherButton", true);
            dataGrid.Add("OtherButtonID", "btnAddModel");
            dataGrid.Add("OtherButtonValue", "导入模型");
            dataGrid.Add("OtherButtonClick", "btnAddModel_Click()");
        }
        dataGrid.Add("ShowBackButton", true);
        dataGrid.Add("ShowPager", true);
        dataGrid.Add("ShowLoading", true);
        @Html.Partial("_GridPanel", dataGrid);
    }
</div>
<div id="ViewPushName" class="viewPushName">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="150">
                编辑推送名称
            </td>
            <td align="right">
                <input type="button" class="button" value="保存" onclick="SavePushName()" />
                <input type="button" class="button" value="关闭" onclick="$('#ViewPushName').hide();$('#DIVMask').hide();" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td height="80" valign="top">
                推送名称：
                <input type="text" id="txt_Schema" style="width: 100px;" />
                .
                <input type="text" id="txt_PushName" style="width: 240px;" />
                <input type="hidden" id="hid_ViewID" />
            </td>
        </tr>
    </table>
</div>
<div id="DIVMask">
</div>
